package cli

import (
	"blockchaingo/block"
	"blockchaingo/wallet"
	"fmt"
	"log"
)

func (cli *CLI) send(from, to string, amount int) {

	if !wallet.ValidateAddress(from) {
		log.Panic("ERROR: Sender address is not valid")
	}

	if !wallet.ValidateAddress(to) {
		log.Panic("ERROR: Sender address is not valid")
	}

	bc := block.NewBlockChain("test")
	defer block.Close(bc)
	fmt.Println("send %s to %s amount %d start!", from, to, amount)
	tx := block.NewUTXOTransaction(from, to, amount, bc)
	cbTx := block.NewCoinbaseTx(from, "")

	b := bc.MineBlock([]*block.Transaction{cbTx, tx})
	utxo := block.UTXOSet{bc}
	utxo.Update(b)
	utxo.Reindex()
	bc.Print()
}
